package com.litchishell.feartures.main;

import com.litchishell.feartures.dao.Predicate;

import java.util.ArrayList;
import java.util.List;

/**
 * @author LitchiShell
 * @description: Predicate--->test
 * @create 2021-11-20
 */
public class PredicateTest {
    public static <T> List<T> filter(List<T> list, Predicate<T> predicate) {
        ArrayList<T> ts = new ArrayList<>();
        for (T t : list) {
            if (predicate.test(t)) {
                ts.add(t);
            }
        }
        return ts;
    }

    public static void main(String[] args) {
        Predicate<String> predicate = (String s) -> !s.isBlank();
        List<String> strings = new ArrayList<>();
        strings.add("1");
        strings.add("");
        strings.add("2");
        strings.add(" ");
        strings.add("3");
        List<String> list = filter(strings, predicate);
        list.forEach(System.out::println);
    }
}
